package vn.mahjonggame.zone;

import java.util.Arrays;
import java.util.Properties;

import vn.mahjonggame.game.request.CreateReplayRoomHandler;
import vn.mahjonggame.metadata.GameActionType;
import vn.mahjonggame.platform.PlatformConfig;
import vn.mahjonggame.zone.event.OnUserJoinZoneHandler;
import vn.mahjonggame.zone.event.OnUserLoginHandler;
import vn.mahjonggame.zone.request.CreateMahjongRoomRequestHandler;
import vn.mahjonggame.zone.request.JoinMahjongRoomRequestHandler;

import com.smartfoxserver.v2.core.SFSEventType;
import com.smartfoxserver.v2.extensions.ExtensionLogLevel;
import com.smartfoxserver.v2.extensions.SFSExtension;

public class MahjongZoneExtension extends SFSExtension {
	
	@Override
	public void init() {		
		addEventHandler(SFSEventType.USER_LOGIN, OnUserLoginHandler.class);
		addEventHandler(SFSEventType.USER_JOIN_ZONE, OnUserJoinZoneHandler.class);		
		
		/*
		 * Create and join room
		 */
		addRequestHandler(GameActionType.createMahjongRoom.toString(),CreateMahjongRoomRequestHandler.class);
		addRequestHandler(GameActionType.joinMahjongRoom.toString(),JoinMahjongRoomRequestHandler.class);		
		addRequestHandler(GameActionType.createReplayRoom.toString(), CreateReplayRoomHandler.class);
		
		Properties properties = getConfigProperties();			
		
		PlatformConfig.configMap.put(PlatformConfig.X_GAME_ID, properties.getProperty(PlatformConfig.X_GAME_ID));
		PlatformConfig.configMap.put(PlatformConfig.X_SECRET_KEY, properties.getProperty(PlatformConfig.X_SECRET_KEY));
		PlatformConfig.configMap.put(PlatformConfig.PLATFORM_URL, properties.getProperty(PlatformConfig.PLATFORM_URL));
		PlatformConfig.configMap.put(PlatformConfig.DEFAULT_AVATAR, properties.getProperty(PlatformConfig.DEFAULT_AVATAR));
		
		PlatformConfig.configMap.put(PlatformConfig.INIT_SCORE, properties.getProperty(PlatformConfig.INIT_SCORE));
		PlatformConfig.configMap.put(PlatformConfig.TUTORIAL_BALANCE, properties.getProperty(PlatformConfig.TUTORIAL_BALANCE));
		
		PlatformConfig.configMap.put(PlatformConfig.TURN_TIME, properties.getProperty(PlatformConfig.TURN_TIME));
		PlatformConfig.configMap.put(PlatformConfig.INIT_BONUS_TIME, properties.getProperty(PlatformConfig.INIT_BONUS_TIME));
		PlatformConfig.configMap.put(PlatformConfig.MAX_ROOM_VARIABLES, properties.getProperty(PlatformConfig.MAX_ROOM_VARIABLES));
		
		PlatformConfig.configMap.put(PlatformConfig.SERVER_MODE, properties.getProperty(PlatformConfig.SERVER_MODE));
		PlatformConfig.configMap.put(PlatformConfig.DYNAMIC_ROOM_NAME, properties.getProperty(PlatformConfig.DYNAMIC_ROOM_NAME));
		PlatformConfig.configMap.put(PlatformConfig.IS_AUTO, properties.getProperty(PlatformConfig.IS_AUTO));		
		
		PlatformConfig.configMap.put(PlatformConfig.PLAYER1, properties.getProperty(PlatformConfig.PLAYER1));
		PlatformConfig.configMap.put(PlatformConfig.PLAYER2, properties.getProperty(PlatformConfig.PLAYER2));
		PlatformConfig.configMap.put(PlatformConfig.PLAYER3, properties.getProperty(PlatformConfig.PLAYER3));
		PlatformConfig.configMap.put(PlatformConfig.PLAYER4, properties.getProperty(PlatformConfig.PLAYER4));
		
		PlatformConfig.configMap.put(PlatformConfig.PICK1, properties.getProperty(PlatformConfig.PICK1));
		PlatformConfig.configMap.put(PlatformConfig.PICK2, properties.getProperty(PlatformConfig.PICK2));
		PlatformConfig.configMap.put(PlatformConfig.PICK3, properties.getProperty(PlatformConfig.PICK3));
		PlatformConfig.configMap.put(PlatformConfig.PICK4, properties.getProperty(PlatformConfig.PICK4));
	}
}